from django.db import models
from apps.common.base.models import BaseModel
from apps.system.payway.models import Payway
from apps.system.lessee.models import Lessee
from  apps.user.models import UserModel

class RecordIncomes(BaseModel):
    '''积分收支记录'''
    payway = (
        ('wxpay', "微信支付"),
        ('alipay', "支付宝支付"),
        ('incomeAndIncomeLocked', "积分组合支付"),
        ('incomes', "资产支付"),
        ('incomesLocked', "专项积分支付"),
        ('golds', "金币支付"),
    )
    scene = (
        ('expense', "消费"),
        ('unlockedIncomes', "锁仓资产释放"),
        ('verticalAward', '直推奖'),
        ('gradeAward', "见点奖"),
        ('incomes', "收益"),
        ('stockCart', '采购'),
        ('agentIncomes', '代理商收益'),
        ('outMoney', '提现'),
        ('outMoneyForRefuse', '提现拒绝返还资产'),
        ('expenseReturn', '退款返还资产'),
        ('addIncomeFromAdmin', "管理员充值"),
        ('subIncomeFromAdmin', "管理员扣除"),
    )
    orderStatus = (
        ("INITIAL", "初始状态"),
        ('WAIT_SEND', "待发送"),
        ('FINISH', "完成"),
        ("REFUSE", "已拒绝"),
    )
    lessee=models.ForeignKey(Lessee, related_name="lessee_recordIncomes", verbose_name='租户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    scene = models.CharField("钱包收支类型", max_length=100, choices=scene, blank=True, null=True)
    user = models.ForeignKey(UserModel, related_name='recordIncomes_set', verbose_name='用户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    fromUser=models.ForeignKey(UserModel, related_name='recordIncomes_from_set', verbose_name='来自用户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    payWayAccount = models.ForeignKey(Payway, related_name='payWayAccount_recordIncomes', verbose_name='收款账户', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    orderId = models.CharField('订单ID', max_length=100, blank=True)
    money=models.DecimalField("金额",max_digits=10, decimal_places=2, default=0)
    balanceIncomes = models.DecimalField("余额积分", max_digits=10, decimal_places=2, default=0)
    serviceCharge=models.DecimalField("服务费",max_digits=10, decimal_places=2, default=0)
    realMoney=models.DecimalField("实际到账",max_digits=10, decimal_places=2, default=0)
    outMoneyTime = models.DateTimeField('处理日期', null=True, blank=True)
    payway=models.CharField("付款类型", choices=payway, max_length=100, blank=True, null=True)
    changeWay = models.CharField("变动方向", max_length=200, blank=True, null=True, default='') #增加/减少
    orderStatus = models.CharField("记录状态", max_length=100, choices=orderStatus, default="INITIAL")
    remark = models.CharField('备注', max_length=200, blank=True, default='')

    class Meta:
        verbose_name = '钱包记录'
        verbose_name_plural = verbose_name